{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "879653da",
   "metadata": {},
   "source": [
    "------------------------------\n",
    "* 本周主要内容： 语音识别\n",
    "* week13\n",
    "* 学习记录：薛欣怡\n",
    "\n",
    "--------------------------------------------"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7cee1685",
   "metadata": {},
   "source": [
    "## 语音识别（优化）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c0698deb",
   "metadata": {},
   "outputs": [],
   "source": [
    "import bdasr"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6a8bedff",
   "metadata": {},
   "source": [
    "## 准备工作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "00999a9d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 准备自己的key\n",
    "\n",
    "API_KEY = 'ONTaiKTnOZAdzNvZF2ENdLQd'\n",
    "SECRET_KEY = 'Hj35fs9FU9o9K5E6IsvQwoeIMbpzhl9E'\n",
    "\n",
    "# 文件路径\n",
    "AUDIO_FILE = 'speech-demo-master/rest-api-asr/python/audio/16k.pcm'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3a81fe87",
   "metadata": {},
   "source": [
    "## 1.语音识别"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e850509a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\"refresh_token\":\"25.9ab710083d00cd11955ac57ba9163189.315360000.1999477596.282335-33296937\",\"expires_in\":2592000,\"session_key\":\"9mzdWT+Lwya42K\\/Yb0ok9h19ZK++HLFEuOP0zKmIiAkhaqm5Q7u1AiuvhiLe7CVfOQaWL2lHJsxdlsfCxHBJlMH58DZBVw==\",\"access_token\":\"24.be0392d9eec45ae8956497a4af2f9bb9.2592000.1686709596.282335-33296937\",\"scope\":\"audio_voice_assistant_get brain_enhanced_asr audio_tts_post brain_speech_realtime public brain_all_scope brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\\u6743\\u9650 vis-classify_flower lpq_\\u5f00\\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\\u5f00\\u653eScope vis-ocr_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 idl-video_\\u865a\\u62df\\u4eba\\u7269\\u52a9\\u7406 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx\",\"session_secret\":\"48893a2e33a6431d5d85c1ccf00bd3ec\"}\n",
      "\n",
      "{'refresh_token': '25.9ab710083d00cd11955ac57ba9163189.315360000.1999477596.282335-33296937', 'expires_in': 2592000, 'session_key': '9mzdWT+Lwya42K/Yb0ok9h19ZK++HLFEuOP0zKmIiAkhaqm5Q7u1AiuvhiLe7CVfOQaWL2lHJsxdlsfCxHBJlMH58DZBVw==', 'access_token': '24.be0392d9eec45ae8956497a4af2f9bb9.2592000.1686709596.282335-33296937', 'scope': 'audio_voice_assistant_get brain_enhanced_asr audio_tts_post brain_speech_realtime public brain_all_scope brain_asr_async wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test权限 vis-classify_flower lpq_开放 cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base smartapp_mapp_dev_manage iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_开放Scope vis-ocr_虚拟人物助理 idl-video_虚拟人物助理 smartapp_component smartapp_search_plugin avatar_video_test b2b_tp_openapi b2b_tp_openapi_online smartapp_gov_aladin_to_xcx', 'session_secret': '48893a2e33a6431d5d85c1ccf00bd3ec'}\n",
      "audio_voice_assistant_get\n",
      "SUCCESS WITH TOKEN: 24.be0392d9eec45ae8956497a4af2f9bb9.2592000.1686709596.282335-33296937  EXPIRES IN SECONDS: 2592000\n",
      "Request time cost 2.216386\n",
      "{\"corpus_no\":\"7233230002982827862\",\"err_msg\":\"success.\",\"err_no\":0,\"result\":[\"北京科技馆。\"],\"sn\":\"996366373621684117597\"}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "xue_token = bdasr.fetch_token(API_KEY,SECRET_KEY)\n",
    "bdasr.asr(xue_token,AUDIO_FILE)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ec08c426",
   "metadata": {},
   "outputs": [],
   "source": [
    "## 2.回复（接入openai）\n",
    "* pip install openai"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bb32e78e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
